package seven.test_7_10;

import java.util.Scanner;

public class TestMain1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = 0;
        int b = 1;
        int count = a + b;
        while (count < n) {
            int tmp = b;
            b = a + b;
            a = tmp;
            count = a + b;
        }
        System.out.println(Math.min(count - n,n - b));
    }
}
